package com.shcz.migu.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.text.TextUtils;

import java.io.IOException;

/**
 * Created by mac on 2017/8/5.
 */

public class MediaLocal {
    public static MediaPlayer initMediaPlayUrl(MediaPlayer mediaPlayer, String url, Context mContext) {
        if (TextUtils.isEmpty(url)) {
//            ToastUtil.show(mContext, mContext.getString(R.string.vedio_url_is_empty));
            return null;
        }
        if (mediaPlayer == null)
            mediaPlayer = new MediaPlayer();
        mediaPlayer.reset();//重置为初始状态
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);//设置音乐流的类型
        try {

            mediaPlayer.setDataSource(mContext, Uri.parse(url));//设置路径
            mediaPlayer.prepare();//缓冲
            mediaPlayer.setLooping(false);
//            mediaPlayer.start();//播放
        } catch (IOException e) {
            e.printStackTrace();
        }
        return mediaPlayer;
    }
}
